//||=========================================================================||
//||                                                                         ||
//||                           MandelbrotCounter.h                           ||
//||                                                                         ||
//||                           by the_best_goose))                           ||
//||                                                                         ||
//||=========================================================================||


#include <QFile>
#include <QLibrary>
#include <string>
#include <stdlib.h>
#include "SimpleMandelbrotCounter.h"
#include "FastComplex.h"

using std::string;

#ifndef MANDELBROTCOUNTER_H_
#define MANDELBROTCOUNTER_H_

//-----------------------------------------------------------------------------

class MandelbrotCounter: public SimpleMandelbrotCounter
{
    Q_OBJECT
public:

    MandelbrotCounter(const MainWindow* pwind, const QWidget* pmand_pic);
    ~MandelbrotCounter();

    static bool IsValid(string mapping);

protected:

    virtual void run();

public slots:

    void SetMapping(string mapping);
    void SetTRe(float re);
    void SetTIm(float im);

    void SetIterPoints(QVector<QPointF> iter_points);

protected:

    virtual void GenerateFile();
    virtual void CompileFile();

    virtual void LoadLibrary();

    virtual void GenLibName();
    virtual string GenFormula();

    string mapping_;
    string file_name_;

    bool is_valid_;

    QFile file_;
    QLibrary lib_;

    typedef void (*CountFunc)(FastComplex t, FastComplex* iter_points,
                              int iter_points_cout, const bool* pbreak,
                              const int* index_array, int iters,
                              int px_width, int px_height, int* pixels,
                              double x, double y, double width, double height,
                              int x_before, int x_after, int y_trans);

    CountFunc pcount_func_;

    QPointF t_;
    bool has_t_;

    int iter_points_count_;
    FastComplex* iter_points_arr_;

    bool has_julia_;
    QPointF c_;
};

//-----------------------------------------------------------------------------

#endif // MANDELBROTCOUNTER_H_
